﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IAD2
{
    abstract class Algorithm
    {
        protected Network net;
        protected List<Neuron> pattern;
        protected double n;
        public Algorithm(Network net, List<Neuron> pattern, double n)
        {
            this.net = net;
            this.pattern = pattern;
            this.n = n;
        }
        abstract public void action(int epocNumber, double eps);

        public void createChart(string name)
        {
            MyChart chart = new MyChart();
            chart.AddSeries(pattern);
            chart.AddSeries(net.points);        
            chart.Save(name);
        }

        public double Error()
        {
            double result = 0;
            int i = 0;
            for ( i = 0; i < net.allPoints.Count; i++)
            {
                net.allPoints[i].Distance = net.allPoints[i].distance(pattern[0]);
                foreach (Neuron tempNeuron in pattern)
                {
                    double di = tempNeuron.distance(net.allPoints[i]);
                    if (di < net.allPoints[i].Distance)
                    {
                        net.allPoints[i].Distance = di;
                    }
                }
                result += net.allPoints[i].Distance;
            }
            return result / i;
        }
    }
}
